import mytest.FjInfo;

import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * xxx
 *
 * @author sdm
 * @version 1.0
 * @date 2023/5/13 15:20
 */
public class test {

    public static void main(String[] args) {
//        String att = "/profile/upload/2023/05/09/logo_20230509163611A001.png,/profile/upload/2023/05/09/LOGO-1024_20230509163613A002.png";
        String att = "/profile/upload/2023/05/19/2d64f873de42cab880726896482dc058_20230519163144A001.jpeg,/profile/upload/2023/05/19/2d64f873de42cab880726896482dc058_20230519163225A002.jpeg,/profile/upload/2023/05/19/70e596423314b2d8a40c267233ac5602_20230519163240A003.jpg";
        String att1 = "";
//        String att1 = "/profile/upload/2023/05/09/logo_20230509163611A001.png";
//        test.getAttachsFormat(att);
//        test.getAttachsFormat(att1);
        test.getAttachsFormat1(att);
        test.getAttachsFormat1(att1);
//        List<FjInfo> infos1 = test.getAttachsFormat(att1);
//        System.out.println(infos1);

//
//        String att2 = "/profile/upload/2023/05/09/logo_20230509163611A001.png";
//        String filePath =  "      data/my/file/myimage.png        ";
//        String mString = getFileNameByPath(filePath);
//        String mString1 = getFileNameByPath(att2);
//        System.out.println(mString1);
//
//
//        String str = "/profile/upload/2023/05/09/logo_20230509163611A001.png";
//        String[] parts = str.split(",");
//        System.out.println("3"+parts);
//        for (String part : parts) {
//            System.out.println(part);
//        }




    }


    public  static  List<FjInfo> getAttachsFormat(String atts) {

        List<FjInfo> fjInfos = new ArrayList<>();
        if (atts == null || atts.equals("")){
            fjInfos.add(new FjInfo("",""));
            return fjInfos;
        }
        String[] strArr = atts.split(",");
        for (String s : strArr) {
            System.out.println(s);
            FjInfo fj = new FjInfo(){{
                setFjName(getFileNameByPath(s));
                setFjUrl(s);
            }};
            fjInfos.add(fj);
        }
        return fjInfos;
    }

    /**
     * 从图片的文件路径中获取图片名字
     * @param path
     * @return
     */
    public static String getFileNameByPath(String path){

        String fName = path.trim();       //删除路径两侧多余空格
        String ImageName = fName.substring(fName.lastIndexOf("/")+1, fName.lastIndexOf("."));//截取最右侧斜杠之右的字段，到点为止
        return ImageName ;
    }


    public static List<FjInfo> getAttachsFormat1(String atts) {

        List<FjInfo> fjInfos = new ArrayList<>();
        if (atts == null || atts.equals("")){
            fjInfos.add(new FjInfo("",""));
            return fjInfos;
        }
        String[] strArr = atts.split(",");
        for (String s : strArr) {
            System.out.println(s);
            FjInfo fj = new FjInfo(){{
                setFjName(Paths.get(s).getFileName().toString());
                setFjUrl(s);
            }};
            fjInfos.add(fj);
        }
        FjInfo fj = new FjInfo();

        // String localhost = getLocalhost();
        for (String s : strArr) {
            fj.setFjName(Paths.get(s).getFileName().toString());
            fj.setFjUrl(s);
            fjInfos.add(fj);
        }
        return fjInfos;
    }

}
